package com.itboye.mengwu.app.ui.main;

import java.util.Observable;
import java.util.Observer;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.mengwu.R;
import com.itboye.mengwu.data.model.ProductAskModel;
import com.itboye.mengwu.data.presenter.ProductAskPresenter;

public class AcitvityBuyAsk extends BaseActivity implements OnClickListener,
		Observer {
	ImageView back;
	TextView txt_title;
	EditText ed;
	TextView ok;
	ProductAskModel askModel;
	ProductAskPresenter askPresenter;
	String uid;
	String pid;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_buyask;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		txt_title.setText("商品咨询");
		uid = SPUtils.get(this, null, SpPublicParams.UID, "") + "";
		pid = getIntent().getStringExtra("pid");
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;
		case R.id.ok: 
			askModel = new ProductAskModel();
			askPresenter = new ProductAskPresenter(this);
			if (ed.getText().toString() != null) {
				askModel.setAsk_content(ed.getText() + "");
				askModel.setAsk_uid(uid);
				askModel.setPid(pid);
			} else {
				ByAlert.alert("咨询内容为空哦");
				return;
			}
			askPresenter.add(askModel);
			ByAlert.alert("已提交");
			finish();
			break;
		default:
			break;
		}
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
		}

	}

}
